"""
暂时用gevent来作为websocket的服务器承载
"""
from gevent import pywsgi
import socketio

sio = socketio.Server()
app = socketio.WSGIApp(sio)


class MyCustomNamespace(socketio.Namespace):
    def on_connect(self, sid, environ):
        print(sid)
        print("app")

    def on_disconnect(self, sid):
        print("dis app")
        print(sid)


sio.register_namespace(MyCustomNamespace('/app'))


class MyCustomNamespace2(socketio.Namespace):
    def on_connect(self, sid, environ):
        print(sid)
        print("camera")

    def on_disconnect(self, sid):
        print(sid)
        print("camera dis")


sio.register_namespace(MyCustomNamespace2('/camera'))

class MyCustomNamespace2(socketio.Namespace):
    def on_connect(self, sid, environ):
        print(sid)
        print("algo")

    def on_disconnect(self, sid):
        print(sid)
        print("algo dis")


sio.register_namespace(MyCustomNamespace2('/algo'))

if __name__ == '__main__':
    pywsgi.WSGIServer(('0.0.0.0', 5000), app).serve_forever()  # 通过gevent来启动5000端口的socket服务
